package Zoo.Handler;


import Zoo.Entity.UserEntity;
import Zoo.Impl.UserServiceImpl;
import Zoo.Service.UserService;
import Zoo.View.UserView.UserView;
import Zoo.View.UserView.UpdateUserView;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class UpdateUserViewHandler implements ActionListener {
    private UpdateUserView updateUserView;
    private UserView userView;

//    public AddAnimalViewHandler(AddZoomenView addZoomenView, LeaderView1 leaderView1){
//        this.addZoomenView=addZoomenView;
//        this.leaderView1=leaderView1;
//    }

    public UpdateUserViewHandler(UpdateUserView updateUserView,UserView userView) {
        this.updateUserView=updateUserView;
        this.userView=userView;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        JButton jButton=(JButton) e.getSource();
        String text =jButton.getText();
        if("修改".equals(text)){
            UserService userService=new UserServiceImpl();
            UserEntity userEntity =updateUserView.buildUpdatedUserEntity();
            boolean updateResult=userService.update(userEntity);
            if(updateResult){
                //重新加载表格查到最新数据
                userView.reloadTable();
                updateUserView.dispose();
            }else{
                JOptionPane.showMessageDialog(updateUserView,"修改失败");

            }

        }
    }

}
